# -- coding: utf-8 --
from wnboss05.action.ai import PurchaseRegistration, CollectionRegistration
from wnboss05.action.case import TestCase
from wnboss05.action.common import Common
from wnboss05.tools.util import excepter, FileParser


class PurchaseRegistrationTest(TestCase):

    @excepter('ai_test.PurchaseRegistrationTest.setup')
    def setup(self):
        # 1.使用对应的角色账号登录；2.进入这个页面
        info = eval(FileParser.parse_ini_by_option('../conf/base.ini', 'login', 'pr'))
        self.pr = PurchaseRegistration()
        Common().do_login(*info)

    @excepter('ai_test.PurchaseRegistrationTest.test_add_assets')
    def test_add_assets(self):
        add_assets_info = FileParser.parse_excel('../conf/case.ini', 'pr', 'add_assets')
        for data in add_assets_info:
            actual = self.pr.do_add_assets(data['data'])
            self.assert_equal(data, actual)

    @excepter('ai_test.PurchaseRegistrationTest.test_query_assets')
    def test_query_assets(self):
        query_assets_info = FileParser.parse_excel('../conf/case.ini', 'pr', 'query_assets')
        for data in query_assets_info:
            actual = self.pr.do_query_assets(data['data'])
            self.assert_equal(data, actual)

    def test_modify_assets(self):
        pass

    @excepter('ai_test.PurchaseRegistrationTest.teardown')
    def teardown(self):
        Common().do_logout()


class CollectionRegistrationTest(TestCase):

    def setup(self):
        # 1.使用对应的角色账号登录；2.进入这个页面
        info = FileParser.read_json('../conf/base.json')
        cr_info = eval(info['cr'])   # 采购登记的前置动作信息
        Common().do_login(*cr_info)

    def teardown(self):
        Common().do_logout()

    def test_add_back_record(self):
        testdata = FileParser.read_json('../data/testdata.json')['cr']
        back_record_data = testdata['add_back_record']
        cr = CollectionRegistration()
        for data in back_record_data:
            actual = cr.do_add_back_record(data)
            self.assert_equal(data, actual)

    def test_back(self):
        testdata = FileParser.read_json('../data/testdata.json')['cr']
        back_data = testdata['back']
        cr = CollectionRegistration()
        for data in back_data:
            actual = cr.do_back()
            self.assert_equal(data, actual)


if __name__ == '__main__':
    prt = PurchaseRegistrationTest()
    prt.setup()
    prt.test_query_assets()


